package com.wyj.config;

import com.wyj.interceptor.DateInterceptor;
import com.wyj.interceptor.LoginRequiredInterceptor;
import com.wyj.interceptor.LoginTicketInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 王永杰
 * @Description 我们写完拦截器后想要其发挥作用的话 那么话我们需要 对其进行配置
 * @since 2022/7/7
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    LoginTicketInterceptor loginTicketInterceptor;

    @Autowired
    LoginRequiredInterceptor loginRequired;

    @Autowired
    DateInterceptor dateInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截所有的请求 除了下方的部分
        registry.addInterceptor(loginTicketInterceptor)
                .excludePathPatterns("/**/*.css","/**/*.js,","/**/*.png","/**/*.jpg","/**/*.jpeg");

//        //设置拦截器 loginRequired 我们在走任何请求的时候 都会进行一些处理  比如检查登录凭证是否过期的问题
//        registry.addInterceptor(loginRequired)
//                .excludePathPatterns("/**/*.css","/**/*.js,","/**/*.png","/**/*.jpg","/**/*.jpeg");
        registry.addInterceptor(dateInterceptor)
                .excludePathPatterns("/**/*.css","/**/*.js,","/**/*.png","/**/*.jpg","/**/*.jpeg");

    }
}
